#include <Hittable.hpp>

void HittableList::ClearObjects() { mObjects.clear(); }

void HittableList::AddObject(std::shared_ptr<Hittable> object) {
  mObjects.emplace_back(std::move(object));
}

bool HittableList::Hit(const Ray& ray, float t_min, float t_max,
                       HitRecord& rec) const {
  HitRecord temp_rec;
  bool hit_anything = false;
  float closest_so_far = t_max;

  for (auto const& object : mObjects) {
    if (object->Hit(ray, t_min, closest_so_far, temp_rec)) {
      hit_anything = true;
      closest_so_far = temp_rec.t;
      rec = temp_rec;
    }
  }

  return hit_anything;
}
